package com.visionet.school.app.web.wechat.vo;


import com.visionet.school.app.web.common.utilities.props.PropsKeys;
import com.visionet.school.app.web.common.utilities.props.PropsUtil;
import com.visionet.school.app.web.wechat.utils.GetToken;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.MessageFormat;



public class MainVO  implements Serializable{

	private static final long serialVersionUID = 9041982489523310886L;

	public static String wechatSignUrl = PropsUtil.getProperty(PropsKeys.WECHAT_SIGN_URL);
	public static String wechatBindUrl = PropsUtil.getProperty(PropsKeys.WECHAT_BIND_URL);
    public static String wechatUrl = PropsUtil.getProperty(PropsKeys.WECHAT_URL);
    public static String appid = PropsUtil.getProperty(PropsKeys.WECHAT_APPID);
    public static String secret = PropsUtil.getProperty(PropsKeys.WECHAT_SECRET);

	/*
	 * 获取token url,method参照微信名称
	 */
	public static String GetTokenUrl()
	{		
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", appid,secret);
		return urlString;		
	}
	
	/*
	 * 获取菜单相关url,method参照微信名称
	 */
	public static String GetMenuUrl(String method)
	{		
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/menu/{0}?access_token={1}",method, GetToken.getToken());
		return urlString;		
	}
	/*
	 * 获取用户相关url,method参照微信名称
	 */
	public static String GetUserUrl(String method)
	{		
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/user/{0}?access_token={1}",method, GetToken.getToken());
		return urlString;	
	}
	/*
	 * 向用户发送客服消息,method参照微信名称
	 */
	public static String GetMessageCustomUrl(String method)
	{		
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/message/custom/{0}?access_token={1}",method, GetToken.getToken());
		return urlString;
	}
	/*
	 * 媒体文件路径
	 */
	public static String GetMediaUrl(String method,String media_type)
	{
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/media/{0}?access_token={1}&type={2}",method, GetToken.getToken(),media_type);
		return urlString;
	}
	/*
	 * 获得下载媒体文件路径
	 */
	public static String GetDownLoadMediaUrl(String media_id)
	{
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", GetToken.getToken(),media_id);
		return urlString;
	}
	
	/*
	 * 获取微信Access_Code
	 */
	public static String GetAccessCode(String redirect_uri)
	{		
		try {
			redirect_uri=URLEncoder.encode(redirect_uri,"utf-8");
		} catch (UnsupportedEncodingException e) {
			
		}
		String urlString=MessageFormat.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_base&state=1#wechat_redirect",appid,redirect_uri);
		return urlString;
	}
	
	/*
	 * 获取微信Access_Code
	 * snsapi_base 静默授权
	 * snsapi_userinfo 获取用户信息，需要用户授权
	 */
	public static String GetUserinfoAccessCode(String redirect_uri)
	{		
		try {
			redirect_uri=URLEncoder.encode(redirect_uri,"utf-8");
		} catch (UnsupportedEncodingException e) {
			
		}
		String urlString=MessageFormat.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri={1}&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect",appid,redirect_uri);
		return urlString;
	}
	/*
	 * 根Access_Code获取微信OpenID
	 */
	public static String GetOpenID(String code)
	{
		String urlString=MessageFormat.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code",appid,secret,code);
		return urlString;
	}
	/*
	 * 消息模板,method参照微信名称
	 */
	public static String GetTemplateUrl(String method)
	{		
		String urlString=MessageFormat.format("https://api.weixin.qq.com/cgi-bin/message/template/{0}?access_token={1}",method, GetToken.getToken());
		return urlString;
	}
	/*
	 * 获取微信用户信息
	 */
	public static String GetUserInfo(String accessToken, String openId)
	{
		String urlString=MessageFormat.format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", accessToken,openId);
		return urlString;
	}

	/**
	 * 获取js sdk的ticket
	 * @return
	 */
	public static String GetJsapiTicket(){
		String urlString = MessageFormat.format("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={0}&type=jsapi",GetToken.getToken());
		return urlString;
	}


	/**
	 * 批量为用户打标签
	 * @return
	 */
	public static String addTastoMembers(){
		String urlString = MessageFormat.format("https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={0}",GetToken.getToken());
		return urlString;
	}

	/**
	 * 个性化菜单
	 * @return
	 */
	public static String individuationMenu(){
		String urlString = MessageFormat.format("https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token={0}",GetToken.getToken());
		return urlString;
	}

	
}
